package service;

import model.Video;
import java.util.ArrayList;
import java.util.List;

public class VideoService {
    private final List<Video> videos = new ArrayList<>();
    private final static VideoService instance = new VideoService();

    private VideoService() {
        // 初始化一些测试数据
        videos.add(new Video("1", "示例视频1", "/videos/sample1.mp4"));
        videos.add(new Video("2", "示例视频2", "/videos/sample2.mp4"));
    }

    public static VideoService getInstance() {
        return instance;
    }

    public List<Video> getAllVideos() {
        return new ArrayList<>(videos);
    }

    public Video getVideoById(String id) {
        for (Video video : videos) {
            if (video.getId().equals(id)) {
                video.incrementViewCount();
                return video;
            }
        }
        return null;
    }

    public void addVideo(Video video) {
        videos.add(video);
    }

    public boolean deleteVideo(String id) {
        return videos.removeIf(v -> v.getId().equals(id));
    }
}
